home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / rb3d / source / rb3d.c next >
Encoding:
C/C++ Source or Header  |  1994-06-01  |  3.3 KB  |  111 lines

  1. #include <egb.h>
  2. #include <snd.h>
  3. #include <malloc.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <io.h>
  7. #include <stat.h>
  8. #include <fcntl.h>
  9. #include "userlib.h"
  10. #include "rb3dh.c"
  11.  
  12. #define VER "1.00"
  13. #define ptor(n) ((n>>5)&31)
  14. #define ptog(n) ((n>>10)&31)
  15. #define ptob(n) (n&31)
  16.  
  17. char egb_work[EgbWorkSize];
  18.  
  19. void pushb ( void )
  20. {
  21.     int a,b;
  22.     do
  23.     {
  24.         SND_joy_in_1(0,&a);            /* マウス・パッド ポート0読み込み */
  25.         SND_joy_in_1(1,&b);            /* マウス・パッド ポート1読み込み */
  26.     }
  27.     while
  28.     ((a&48)==48 &&(b&48)==48);        /* ボタンを押すまで繰り返す */
  29.     if((a&32)+(b&32)!=64) exit(0);    /* マウス左かパッドBなら終了 */
  30. }
  31.  
  32. void main ( int argc,char *argv[] )
  33. {
  34.     char *buf;
  35.     int x,y,n=0,p,f;
  36.     char name[80];
  37.  
  38.     buf=malloc(320*240*2);
  39.     if(argc<2 || buf==NULL)
  40.     {
  41.         puts("Red and Blue 3D Graphics Maker RB3D.EXP  Version " VER);
  42.         puts("  Copyright (c) Namy 1993. All rights reserved.\n");
  43.         puts("    Usage : RUN386 RB3D [OutputFile] ([Start No.])");
  44.         exit(0);
  45.     }
  46.     if(argc>2) n=atoi(argv[2]);
  47.  
  48.     EGB_init(egb_work,EgbWorkSize);    /* EGB初期化 */
  49.     EGB_resolution(egb_work,0,11);    /* PAGE0 320*240 32768色 インタレース */
  50.     EGB_resolution(egb_work,1,11);    /* PAGE1 320*240 32768色 インタレース */
  51.  
  52.     LOOP:;
  53.     EGB_displayPage(egb_work,0,1);    /* PAGE0を前 PAGE0を表示 PAGE1を非表示 */
  54.     EGB_writePage(egb_work,0);        /* アクティブページを0に */
  55.     EGB_digitize(egb_work,1);        /* ページ0ビデオデジタイズ開始 */
  56.     pushb();                        /* ボタンを押すのを待つ    */
  57.  
  58.     EGB_digitize(egb_work,0);        /* ビデオデジタイズ停止 */
  59.     USR_getBlock(egb_work,buf,0,0,319,239);
  60.                                     /* 画面をbufに複写 */
  61.     EGB_writePage(egb_work,1);        /* アクティブページを1に */
  62.     EGB_clearScreen(egb_work);        /* ページ1を消去 */
  63.     EGB_displayPage(egb_work,1,2);    /* PAGE1を前 PAGE0を非表示 PAGE1を表示 */
  64.     EGB_maskBit(egb_work,0x001f001f);
  65.                     /* ハードウェアマスク設定 0000000000011111 (青だけ) */
  66.     for(y=0;y<240;y++)
  67.     {
  68.         for(x=0;x<320;x++)
  69.         {
  70.             p=*((short*)(buf+(y*320+x)*2));
  71.             *((short*)(buf+(y*320+x)*2))=(ptor(p)+ptog(p)+ptob(p))/3;
  72.                     /* RGBに分解し平均をとる = モノクロにする */
  73.         }
  74.         USR_putBlock(egb_work,buf+y*320*2,0,0,y,319,y);
  75.     }
  76. /*    USR_putBlock(egb_work,buf,0,0,0,319,239);*/
  77.  
  78.     EGB_displayPage(egb_work,0,1);    /* PAGE0を前 PAGE0を表示 PAGE1を非表示 */
  79.     EGB_writePage(egb_work,0);        /* アクティブページを0に */
  80.     EGB_digitize(egb_work,1);        /* ページ0ビデオデジタイズ開始 */
  81.     pushb();                        /* ボタンを押すのを待つ    */
  82.  
  83.     EGB_digitize(egb_work,0);        /* ビデオデジタイズ停止 */
  84.     USR_getBlock(egb_work,buf,0,0,319,239);
  85.                                     /* 画面をbufに複写 */
  86.     EGB_writePage(egb_work,1);        /* アクティブページを1に */
  87.     EGB_displayPage(egb_work,1,2);    /* PAGE1を前 PAGE0を非表示 PAGE1を表示 */
  88.     EGB_maskBit(egb_work,0x03e003e0);
  89.                     /* ハードウェアマスク設定 0000001111100000 (赤だけ) */
  90.     for(y=0;y<240;y++)
  91.     {
  92.         for(x=0;x<320;x++)
  93.         {
  94.             p=*((short*)(buf+(y*320+x)*2));
  95.             *((short*)(buf+(y*320+x)*2))=((ptor(p)+ptog(p)+ptob(p))/3)<<5;
  96.                     /* RGBに分解し平均をとる = モノクロにする */
  97.         }
  98.         USR_putBlock(egb_work,buf+y*320*2,0,0,y,319,y);
  99.     }
  100. /*    USR_putBlock(egb_work,buf,0,0,0,319,239);*/
  101.  
  102.     USR_getBlock(egb_work,buf,0,0,319,239);
  103.     sprintf(name,"%s%d.tif",argv[1],n);
  104.     f=open(name,O_BINARY|O_CREAT|O_WRONLY,S_IREAD|S_IWRITE);
  105.     write(f,tifhead,512);            /* TIFFヘッダ書き込み */
  106.     write(f,buf,320*240*2);
  107.     close(f);
  108.     n++;
  109.     goto LOOP;
  110. }
  111.